﻿using System;
using System.Configuration;
using StockholmsStad.Utilities.Exceptions;
using StockholmsStad.Utilities.Enums;

namespace StockholmsStad.Utilities
{
    public class SettingsUtility
    {
        public static string GetConnectionString(string key)
        {
            if(string.IsNullOrEmpty(key))
                throw new ArgumentNullException("key");

            if (ConfigurationManager.ConnectionStrings == null || ConfigurationManager.ConnectionStrings.Count <= 0)
                throw new StockholmStadApplicationException(ApplicationErrorCode.ConnectionStringMissing, Severity.High);

            return ConfigurationManager.ConnectionStrings[key].ConnectionString;
        }

        public static string GetAppSetting(string key)
        {
            if(string.IsNullOrEmpty(key))
                throw new ArgumentNullException("key");

            if(ConfigurationManager.AppSettings == null || ConfigurationManager.AppSettings.Count <= 0)
                throw new StockholmStadApplicationException(ApplicationErrorCode.AppSettingKeyMissing, Severity.High);

            return ConfigurationManager.AppSettings[key];
        }
    }
}
